package kgc.crm.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import kgc.crm.mapper.ContractMapper;
import kgc.crm.model.Contract;
import kgc.crm.service.IContractService;
import kgc.crm.util.EmptyChecker;
import kgc.crm.util.ResultUtil;
import kgc.crm.vo.ContractVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

//合同Service实现impl
@Slf4j
@Service
public class ContractServiceImpl extends ServiceImpl<ContractMapper,Contract> implements IContractService  {
    @Autowired
    private ContractMapper contractMapper;

    @Override
    public ResponseEntity listAndPage(ContractVo vo) {
        if (EmptyChecker.isEmpty(vo)) {
            log.error("【合同模块】查询合同失败,vo对象不能为空",vo);
            return ResultUtil.error("查询失败");
        }
        if (vo.getPageIndex() <= 0 || vo.getPageIndex() == null) {
            vo.setPageIndex(1);
        }
        if (vo.getPageSize() <= 0 || vo.getPageSize() == null) {
            vo.setPageSize(10);
        }
        List<Contract> list = contractMapper.listAndPage((vo.getPageIndex()-1)*vo.getPageSize(), vo.getPageSize());
        return ResultUtil.success(list);
    }
}
